package lk.icta.core.dao.impl;

import lk.icta.common.dao.impl.BaseDAO;
import lk.icta.core.dao.MortgageDAO;
import lk.icta.core.entity.Mortgage;
import lk.icta.user.entity.User;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Duminda Dharmakeerthi
 */
public class MortgageDAOImpl extends BaseDAO implements MortgageDAO {

    @Transactional(propagation = Propagation.MANDATORY)
    public void addMortgage(Mortgage mortgage, User user) {
        logger.debug("Add Mortgage details [Bank/Institute {}]", mortgage.getNameOfBank());
        em.persist(mortgage);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    public void updateMortgage(Mortgage mortgage, User user) {
        logger.debug("Updating Mortgage Details [Mortgage ID: {}]", mortgage.getId());
        em.merge(mortgage);
    }
}
